<#assign object = doc.objects>
package ${object.package}.client;

import redora.rdo.client.model.AttributeFieldsView;
import redora.rdo.client.upgrade.RedoraConfigurationViewPanel;
<#list object["/objects/object/name"] as objectName>
import ${object.package}.gwt.client.${objectName}ViewPanel;
</#list>

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FlexTable;

public class GWTShowcase implements EntryPoint {

	public void onModuleLoad() {

		final DecoratedTabPanel dataTp = new DecoratedTabPanel();
		<#list object["/objects/object/name"] as objectName>
		final ${objectName}ViewPanel ${objectName?uncap_first}Panel = new ${objectName}ViewPanel();
		dataTp.add(${objectName?uncap_first}Panel, "${objectName?uncap_first}");
		</#list>
		dataTp.setHeight("500");
		dataTp.setWidth("100%");
		dataTp.setVisible(true);
		dataTp.addSelectionHandler(new SelectionHandler<Integer>() {

			public void onSelection(SelectionEvent<Integer> arg0) {
				<#assign num = 0>
				<#list object["/objects/object/name"] as objectName>
				if(arg0.getSelectedItem() == ${num}) {
					${objectName?uncap_first}Panel.setVisible(true);
				}
				<#assign num = num + 1>
				</#list>
			}

		});

		final DecoratedTabPanel attributeTp = new DecoratedTabPanel();
		<#list object["/objects/object/name"] as objectName>
		attributeTp.add(new AttributeFieldsView("${objectName}"), "${objectName?uncap_first}");
		</#list>
		attributeTp.setHeight("500");
		attributeTp.setWidth("100%");
		attributeTp.setVisible(false);
		attributeTp.addSelectionHandler(new SelectionHandler<Integer>(){

			public void onSelection(SelectionEvent<Integer> arg0) {
				AttributeFieldsView panel = (AttributeFieldsView) attributeTp
						.getWidget(arg0.getSelectedItem());
				panel.setVisible(true);
			}
			
		});
		
		final FlowPanel upgradeFp = new FlowPanel();
		final RedoraConfigurationViewPanel redoraConfigurationViewPanel = new RedoraConfigurationViewPanel();
		upgradeFp.add(redoraConfigurationViewPanel);
		upgradeFp.setVisible(false);

				FlexTable table = new FlexTable();
		
		Hyperlink modelLink = new Hyperlink();
		modelLink.setText("Model");
		modelLink.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(false);
				attributeTp.setVisible(true);
				upgradeFp.setVisible(false);
			}

		});
		table.setWidget(0, 0, modelLink);
		
		Hyperlink dataLink = new Hyperlink();
		dataLink.setText("Data");
		dataLink.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(true);
				attributeTp.setVisible(false);
				upgradeFp.setVisible(false);
			}

		});
		table.setWidget(0, 1, dataLink);
		
		Hyperlink upgradeLink = new Hyperlink();
		upgradeLink.setText("Upgrade");
		upgradeLink.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(false);
				attributeTp.setVisible(false);
				upgradeFp.setVisible(true);
				redoraConfigurationViewPanel.setVisible(true);
			}

		});
		table.setWidget(0, 2, upgradeLink);
		
		Hyperlink taggingLink = new Hyperlink();
		taggingLink.setText("Tagging");
		taggingLink.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(false);
				attributeTp.setVisible(false);
				upgradeFp.setVisible(false);
			}

		});
		table.setWidget(0, 3, taggingLink);

		VerticalPanel panel = new VerticalPanel();
		panel.setHeight("1000");
		panel.setWidth("100%");

		RootPanel.get().add(panel);
		panel.add(table);

		VerticalPanel showPanel = new VerticalPanel();

		showPanel.add(dataTp);
		showPanel.add(attributeTp);
		showPanel.add(upgradeFp);
		showPanel.setWidth("100%");
		showPanel.setHeight("100%");

		panel.add(showPanel);
		RootPanel.getBodyElement().removeChild(
				RootPanel.get("loadingWrapper").getElement());
	}

}